import 'package:app_router_demo/config/app_router.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:flutter/material.dart';

class AuthProvider with ChangeNotifier {
  bool _isChecked = false;
  bool _isLoggedIn = false;
  bool get isLoggedIn => _isChecked;

  bool get isChecked => _isChecked;

  void toggleCheckbox(bool? newValue) {
    _isChecked = newValue ?? false;
    notifyListeners();
  }

  // You might add methods for actual sign-in logic here,
  // which would then interact with your authentication service.
  Future<void> signInWithApple() async {
    // Implement Apple sign-in logic
    print('Sign in with Apple tapped');
    // ...
  }

  Future<void> signInWithFacebook() async {
    // Implement Facebook sign-in logic
    print('Sign in with Facebook tapped');
    // ...
  }

  Future<void> signInWithGoogle() async {
    // Implement Google sign-in logic
    print('Sign in with Google tapped');
    // ...
  }

  Future<void> signInWithEmail() async {
    // Implement Email sign-in logic
    print('Sign in with Email tapped');
    // ...
  }
}

class AuthGuard extends AutoRouteGuard {
  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    final context = router.navigatorKey.currentContext!;
    final auth = Provider.of<AuthProvider>(context, listen: false);

    if (auth.isLoggedIn) {
      resolver.next(true); // 放行
    } else {
      router.replace(const LoginRoute()); // 重定向到登录页
    }
  }
}
